package com.tanhua.server.service.impl;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.tanhua.common.mapper.UserInfoMapper;
import com.tanhua.common.pojo.UserInfo;
import com.tanhua.server.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;

@Service
public class UserInfoServiceImpl implements UserInfoService {

    @Autowired
    private UserInfoMapper userInfoMapper;

    /**
     * 根据用户的id查询用户的信息
     * @param id
     * @return
     */
    @Override
    public UserInfo queryUserInfoByUserId(Long id) {

        /*LambdaQueryWrapper<UserInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserInfo::getUserId,id);*/
        QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",id);
        return this.userInfoMapper.selectOne(queryWrapper);
    }

    /**
     * 根据满足以下条件的ids集合来查询对应的userinfo列表
     * @param queryWrapper
     * @return
     */
    /*  //用户id参数
        queryWrapper.in("user_id", userIds);
        //需要性别参数查询
        if (StringUtils.isEmpty(queryParam.getCity())){
            queryWrapper.eq("sex", StringUtils.equals(queryParam.getGender(), "man") ? 1:2);
        }
        //需要城市参数查询
        if (StringUtils.isNotEmpty(queryParam.getCity())){
            queryWrapper.like("city", queryParam.getCity());
        }
        //设置年龄参数，条件：小于等于
        if (queryParam.getAge() != null){
            queryWrapper.le("age",queryParam.getAge());
        }
    */
    @Override
    public List<UserInfo> queryUserInfoList(QueryWrapper<UserInfo> queryWrapper) {
        return this.userInfoMapper.selectList(queryWrapper);
    }

    /**
     * 根据用户id的集合查询用户列表
     * @param userIds
     * @return
     */
    @Override
    public List<UserInfo> queryUserInfoByUserIdList(List<Object> userIds) {
        QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("user_id", userIds);

        List<UserInfo> userInfoList = queryUserInfoList(queryWrapper);


        return userInfoList;

    }

    /**
     * 修改用户信息
     *
     * @param userInfo
     * @return
     */
    @Override
    public Boolean updateUserInfoByUserId(UserInfo userInfo) {
        QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userInfo.getUserId());
        int updateCount = this.userInfoMapper.update(userInfo, queryWrapper);
        return updateCount > 0;
    }
}
